package demo;

public class Computer {

    public static void serive(IUSB str) {
        str.open();
       if (str instanceof Mouse) {
           //向下转型,因为IUSB接口内没有mouseSerive方法
           Mouse mouse = (Mouse) str;
           mouse.mouseSerive();
       }else if (str instanceof KeyBoard) {
           //向下转型,因为IUSB接口内没有keyBoardSerive方法
           KeyBoard keyBoard = (KeyBoard) str;
           keyBoard.keyBoardSerive();
       }
       str.close();
    }
    public static void main(String[] args) {
        //Mouse的匿名对象传给servie方法
        serive(new Mouse());
        //KeyBoard的匿名对象传给servie方法
        serive(new KeyBoard());
    }
}
